<?php
/**
 * Created by PhpStorm.
 * User: meng
 * Date: 2023/9/5
 * Time: 15:09
 */

namespace app\admin\controller;

use app\admin\service\MenuService;
use app\admin\validator\MenuValidator;
use lib\common\CommonController;
use lib\annotations\Permission;

class Menu extends CommonController
{
    /**
     * @Permission
     * @param MenuService $service
     * @return void
     */
    public function index (MenuService $service): void {
        $data = $service->menuList(true);
        $this->success($data);
    }

    /**
     * @Permission
     * @param $id
     * @param MenuService $service
     * @return void
     */
    public function get ($id, MenuService $service): void {
        $data = $service->findMenu($id);
        $this->success($data);
    }

    /**
     * @Permission
     * @param MenuService $service
     * @return void
     */
    public function create (MenuService $service): void {
        $params = $this->request->all();
        (new MenuValidator())->goCheck($params, 'create');
        $service->create($params);
        $this->success();
    }

    /**
     * @Permission
     * @param $id
     * @param MenuService $service
     * @return void
     */
    public function update ($id, MenuService $service): void {
        $params = $this->request->all();
        (new MenuValidator())->goCheck($params, 'update');
        $service->update($id, $params);
        $this->success();
    }

    /**
     * @Permission
     * @param $id
     * @param MenuService $service
     * @return void
     */
    public function delete ($id, MenuService $service): void {
        $service->delete($id);
        $this->success();
    }
}
